package org.jeecg.modules.charge.service.impl;

import org.jeecg.common.util.StringUtils;
import org.jeecg.entity.charge.ChargeBills;
import org.jeecg.modules.charge.entity.ChargeBillsOrder;
import org.jeecg.modules.charge.mapper.ChargeAppMapper;
import org.jeecg.modules.charge.service.IChargeAppService;
import org.jeecg.modules.charge.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 战图收缴率
 * @Author: Lee
 * @Date:   2019-08-22
 * @Version: V1.0
 */
@Service
public class ChargeAppServiceImpl  implements IChargeAppService {
    @Autowired
    private ChargeAppMapper chargeAppMapper;


    @Override
    public List<ChargeBills> getBillsByRoomId(String roomId, String feeType, String cusOrRent) {
        List<ChargeBills> bills=chargeAppMapper.getBillsByRoomId(roomId,feeType,cusOrRent);
        return bills;
    }

    @Override
    public ChargePayRecordsByRoom getPayRecordsByRoom(String roomId) {
        ChargePayRecordsByRoom record=chargeAppMapper.getPayRecordsByRoom(roomId);
        return record;
    }

    @Override
    public List<ChargeBillsOrder> getPayRecordsByUid(String userId) {
        List<ChargeBillsOrder> orders = chargeAppMapper.getPayRecordsByUid(userId);
        if (null != orders && orders.size() > 0) {
            for (ChargeBillsOrder order : orders) {
                if (null != order.getBillids() && StringUtils.isNotEmpty(order.getBillids())) {
                    List<String> bids = new ArrayList<String>();
                    String[] billids = order.getBillids().split(",");
                    for (int i = 0; i < billids.length; i++) {
                        bids.add(billids[i]);
                    }
                    String cnys=chargeAppMapper.getCnysByBids(bids);
                    order.setTypeName(cnys+" "+order.getTypeName());
                }
            }
        }
        return orders;
    }
    @Override
    public String getNameByTenantId(String tenantId) {
        String orders=chargeAppMapper.getNameByTenantId(tenantId);
        return orders;
    }

    @Override
    public String getCnysByBids(List<String> billids) {
        return chargeAppMapper.getCnysByBids(billids);
    }

/*    @Override
    public TreeMap<String, List<BaseFloorAndRoom>> getFloorsAndRoomsByPid(String pid) {
        TreeMap<String, List<BaseFloorAndRoom>> floorAndRooms=null;
        List<BaseFloorAndRoom> floors=chargeAppMapper.getFloorsByPid(pid);
        if(null!=floors && floors.size()>0){
            floorAndRooms=new   TreeMap<String, List<BaseFloorAndRoom>>();
            for(BaseFloorAndRoom floor:floors){
              List<BaseFloorAndRoom> rooms=chargeAppMapper.getRoomsByFid(floor.getFloorId());
              if(null!=rooms && rooms.size()>0){
                  floorAndRooms.put(floor.getFloorName(),rooms);
              }
            }
        }

        return floorAndRooms;
    }*/

    @Override
    public List<ChargeAppProperty>  getBaseInfos() {
        List<ChargeAppProperty> projects=chargeAppMapper.getBaseInfos();
        if(null!=projects && projects.size()>0){
        for(ChargeAppProperty project:projects){
        List<ChargeAppProperty> floors=chargeAppMapper.getFloorsByPid(project.getPid());
        if(null!=floors && floors.size()>0){
            project.setChild(floors);
            for (ChargeAppProperty floor:floors){
                List<ChargeAppProperty> rooms= chargeAppMapper.getRoomsByFid(floor.getPid());
                if(null!=rooms && rooms.size()>0){
                    floor.setChild(rooms);
                }
            }
        }
        }
        }
        return projects;
    }
    @Override
    public String getRepair(String repairNo) {
        String orders=chargeAppMapper.getRepair(repairNo);
        return orders;
    }
    @Override
    public  List<ChargeBillsOrder> getPayCarByUid(String userId){
        List<ChargeBillsOrder> orders=chargeAppMapper.getPayCarByUid(userId);
        return orders;
    }
}
